package org.shj.excel;

import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.support.ExcelTypeEnum;
import org.shj.utils.DateUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author Shen Huang Jian
 * @date 2019-08-12 9:50
 */
public class EasyExcelDemo {

    public static void main(String[] args){

        try {

            String template = "/template/user_log_export.xlsx";
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(template);

            List<Object> data = EasyExcelFactory.read(is, new Sheet(1, 1));

            FileOutputStream out = new FileOutputStream(new File("d:\\tmp\\test.xlsx"));
            ExcelWriter writer = new ExcelWriter(is, out, ExcelTypeEnum.XLSX, true);
            Sheet sheet1 = new Sheet(1, 2);
            sheet1.setSheetName("sheet1");

            //sheet1.set

            writer.write0(getAllUserLogs(), sheet1);
            writer.finish();

            out.flush();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private static List<List<String>> getAllUserLogs(){
        List<List<String>> results = new ArrayList<>();
        List<String> row = Arrays.asList("aa", "bb", "cc");
        results.add(row);
        return results;
    }
}
